/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import entitybean.Songs;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import sessionbean.AlbumSessionBeanRemote;
import sessionbean.ArtistsSessionBeanRemote;
import sessionbean.CommentsSessionBeanRemote;
import sessionbean.CountrySessionBeanRemote;
import sessionbean.GenresSessionBeanRemote;
import sessionbean.MusiciansSessionBeanRemote;
import sessionbean.ProducersSessionBeanRemote;
import sessionbean.SongsSessionBean;
import sessionbean.SongsSessionBeanRemote;
import sessionbean.UploadsSessionBeanRemote;
import sessionbean.UsersSessionBeanRemote;

/**
 *
 * @author ShahanThai
 */
public class ControllerServlet extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String button = request.getParameter("btnAction");
            List lastListen = new ArrayList();
            System.out.println(lastListen.size() + "sds");
            Cookie[] cookies = request.getCookies();
            String song1 = null;
            String song2 = null;
            String song3 = null;
            String song4 = null;
            if (cookies != null) {
                Context context = new InitialContext();
                Object obj = context.lookup("SongsJNDI");
                SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                System.out.println(cookies.length);
                for (int i = 0; i < cookies.length; i++) {
                    String name = cookies[i].getName();
                    String value = cookies[i].getValue();
                    System.out.println(cookies[i].getName() + " " + cookies[i].getValue());
                    if (name.equals("1")) {
                        song1 = value;
                    } else if (name.equals("2")) {
                        song2 = value;
                    } else if (name.equals("3")) {
                        song3 = value;
                    } else if (name.equals("4")) {
                        song4 = value;
                    }
                }
                if (song1 != null) {
                    List list = remote.getSong(Integer.parseInt(song1));
                    if (list != null) {
                        lastListen.add(list.get(0));
                    }
                }
                if (song2 != null) {
                    List list = remote.getSong(Integer.parseInt(song2));
                    if (list != null) {
                        lastListen.add(list.get(0));
                    }
                }
                if (song3 != null) {
                    List list = remote.getSong(Integer.parseInt(song3));
                    if (list != null) {
                        lastListen.add(list.get(0));
                    }
                }
                if (song4 != null) {
                    List list = remote.getSong(Integer.parseInt(song4));
                    if (list != null) {
                        lastListen.add(list.get(0));
                    }
                }
            }
            System.out.println(lastListen.size());
            HttpSession session = request.getSession();
            session.setAttribute("LASTLISTEN", lastListen);
            if (button == null) {
                String url = "index.jsp";
                response.sendRedirect(url);
            } else if (button.equals("")) {
                String searchValue = request.getParameter("searchValue");
                String[] findBys = request.getParameterValues("mode");
                String findBy = null, category = null;
                if (findBys != null) {
                    findBy = findBys[0];
                } else {
                    findBy = "*";
                }
                if (findBy.equals("") || findBy.equals("*")) {
                    request.setAttribute("mode", "Tên bài hát/Ca sĩ");
                } else if (findBy.equals("artist")) {
                    request.setAttribute("mode", "Ca sĩ");
                }
                if (findBy.equals("composer")) {
                    request.setAttribute("mode", "Sáng tác");
                }
                if (findBy.equals("album")) {
                    request.setAttribute("mode", "Tên Album");
                }
                if (findBy.equals("lyric")) {
                    request.setAttribute("mode", "Lời bài hát");
                }
                request.setAttribute("searchValue", searchValue);
                String[] categories = request.getParameterValues("cat");
                if (categories != null) {
                    category = categories[0];
                } else {
                    category = "";
                }
                Context context = new InitialContext();
                Object obj = context.lookup("SongsJNDI");
                SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                List list = remote.getSong(searchValue, findBy, category);
                request.setAttribute("LIST", list);
                String url = "search.jsp";
                RequestDispatcher rd = request.getRequestDispatcher(url);
                rd.forward(request, response);
            } else if (button.equals("Redirect")) {
                out.println("This page is constructing");
            } else if (button.equals("Login")) {
                String username = request.getParameter("username");
                String password = request.getParameter("password");
                String autologin = request.getParameter("autologin");
                Context context = new InitialContext();
                Object obj = context.lookup("UsersJNDI");
                UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                boolean result = remote.checkLogin(username, password);
                boolean role = remote.checkRole(username);
                if (autologin == null) {
                    if (result) {
                        session.setAttribute("username", username);
                        if (role == true) {
                            RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=artist");
                            rd.forward(request, response);
                        } else {
                            RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
                            rd.forward(request, response);
                        }
                    } else {
                        response.sendRedirect("loginerror.jsp");
                    }
                } else {
                    if (result) {
                        session.setAttribute("username", username);
                        Cookie cookie = new Cookie("username", username);
                        cookie.setMaxAge(30 * 60);
                        response.addCookie(cookie);
                        if (role == true) {
                            RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=artist");
                            rd.forward(request, response);
                        } else {
                            RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
                            rd.forward(request, response);
                        }
                    } else {
                        response.sendRedirect("loginerror.jsp");
                    }
                }
            } else if (button.equals("Register")) {
                Context context = new InitialContext();
                Object obj = context.lookup("UsersJNDI");
                UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                String username = request.getParameter("username");
                boolean result = remote.checkAvailableUser(username);
                String password = request.getParameter("password");
                String repassword = request.getParameter("repassword");
                String email = request.getParameter("email");
                String e1 = "", e2 = "", e3 = "", e4 = "";
                if (username.equals("")) {
                    e1 = "Tên đăng nhập không được bỏ trống";
                }
                if (result) {
                    e1 = "Tên đăng nhập đã tồn tại";
                }
                if (username.length() < 6 || username.length() > 50) {
                    e1 = "Độ dài tên đăng nhập phải từ 6 đến 50 ký tự";
                }
                if (password.equals("")) {
                    e2 = "Mật khẩu không được bỏ trống";
                }
                if (password.length() < 6 || password.length() > 50) {
                    e2 = "Độ dài mật khẩu phải từ 6 đến 50 ký tự";
                }
                if (!repassword.equals(password)) {
                    e3 = "Mật khẩu nhập lại không giống";
                }
                if (email.equals("")) {
                    e4 = "Email không được bỏ trống";
                }
                if (!e1.equals("") || !e2.equals("") || !e3.equals("") || !e4.equals("")) {
                    request.setAttribute("e1", e1);
                    request.setAttribute("e2", e2);
                    request.setAttribute("e3", e3);
                    request.setAttribute("e4", e4);
                    request.setAttribute("regnuser", username);
                    request.setAttribute("regemail", email);
                    RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
                    rd.forward(request, response);
                } else {
                    Calendar cal = Calendar.getInstance();
                    Date date = cal.getTime();
                    boolean result1 = remote.addUser(username, password, date, email, false, 0);
                    if (result1) {
                        RequestDispatcher rd = request.getRequestDispatcher("registersuccess.jsp");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                }
            } else if (button.equals("Upload")) {
                out.println("Upload page is constructing");
            } else if (button.equals("Listen")) {
                String type = request.getParameter("type");
                String strID = request.getParameter("id");
                int id = 0;
                try {
                    id = Integer.parseInt(strID);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
                if (type.equals("music") || type.equals("video")) {
                    Context context = new InitialContext();

                    Object obj = context.lookup("SongsJNDI");
                    SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                    List list = remote.getSong(id);


                    if (list != null) {
                        List uploader = remote.getUploader(id);
                        List sameArtist = remote.getSongSameArtist(id);
                        List sameGenre = remote.getSongSameGenre(id);
                        List relativeSong = remote.getRelativeSong(id);

                        request.setAttribute("SONG", null);
                        request.setAttribute("UPLOADER", null);
                        request.setAttribute("SAMEARTIST", null);
                        request.setAttribute("RELATIVESONG", null);
                        request.setAttribute("SAMEGENRE", null);

                        request.setAttribute("SONG", list);
                        request.setAttribute("UPLOADER", uploader);
                        request.setAttribute("SAMEARTIST", sameArtist);
                        request.setAttribute("RELATIVESONG", relativeSong);
                        request.setAttribute("SAMEGENRE", sameGenre);

                        Cookie cookie1 = new Cookie("1", strID);
                        cookie1.setMaxAge(30 * 24 * 60 * 60);
                        response.addCookie(cookie1);
                        System.out.println(cookie1.getName() + " " + cookie1.getValue());
                        if (cookies != null) {
                            if (song1 != null && !strID.equals(song1)) {
                                Cookie cookie2 = new Cookie("2", song1);
                                cookie2.setMaxAge(30 * 24 * 60 * 60);
                                response.addCookie(cookie2);
                                System.out.println(cookie2.getName() + " " + cookie2.getValue());
                                if (song2 != null && !strID.equals(song2)) {
                                    Cookie cookie3 = new Cookie("3", song2);
                                    cookie3.setMaxAge(30 * 24 * 60 * 60);
                                    response.addCookie(cookie3);
                                    System.out.println(cookie3.getName() + " " + cookie3.getValue());
                                    if (song3 != null && !strID.equals(song3)) {
                                        Cookie cookie4 = new Cookie("4", song3);
                                        cookie4.setMaxAge(30 * 24 * 60 * 60);
                                        response.addCookie(cookie4);
                                        System.out.println(cookie4.getName() + " " + cookie4.getValue());
                                    }
                                }
                            }
                        }
                    }
                }
                if (type.equals("music")) {
                    String url = "music.jsp";
                    RequestDispatcher rd = request.getRequestDispatcher(url);
                    rd.forward(request, response);
                } else if (type.equals("video")) {
                    String url = "video.jsp";
                    RequestDispatcher rd = request.getRequestDispatcher(url);
                    rd.forward(request, response);
                } else if (type.equals("album")) {
                }
            } else if (button.equals("checkCookie")) {
                if (cookies.length > 0) {
                    for (int i = 0; i < cookies.length; i++) {
                        String name = cookies[i].getName();
                        String value = cookies[i].getValue();
                        if (name.equals("username")) {
                            Context context = new InitialContext();
                            Object obj = context.lookup("UsersJNDI");
                            UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                            boolean role = remote.checkRole(value);
                            if (role == true) {
                                session.setAttribute("username", value);
                                RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=artist");
                                rd.forward(request, response);
                            } else {
                                session.setAttribute("username", value);
                                RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
                                rd.forward(request, response);
                            }
                        }
                    }
                    RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
                    rd.forward(request, response);
                } else {
                    response.sendRedirect("login.jsp");
                }
            } else if (button.equals("Viewinfo")) {
                String username = request.getParameter("id");
                Context context = new InitialContext();
                Object obj = context.lookup("UsersJNDI");
                UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                List list = remote.getUser(username);
                request.setAttribute("list", list);
                RequestDispatcher rd = request.getRequestDispatcher("userinfo.jsp");
                rd.forward(request, response);
            } else if (button.equals("Change")) {
                Context context = new InitialContext();
                Object obj = context.lookup("UsersJNDI");
                UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                String oldpassword = request.getParameter("oldpassword");
                String reoldpassword = request.getParameter("reoldpassword");
                String newpassword = request.getParameter("newpassword");
                String e1 = "", e2 = "", e3 = "";
                if (oldpassword.equals("")) {
                    e1 = "Password cũ không được để trống";
                }
                if (!oldpassword.equals(reoldpassword)) {
                    e2 = "Password nhập lại không trùng";
                }
                if (newpassword.equals("")) {
                    e3 = "Password không được để trống";
                }
                if (newpassword.length() < 6 || newpassword.length() > 50) {
                    e3 = "Độ dài password từ 6 đến 50 ký tự";
                }
                if (e1.equals("") && e2.equals("") && e3.equals("")) {
                    String username = (String) session.getAttribute("username");
                    boolean result = remote.changePassword(username, newpassword);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("changeusersuccess.jsp");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else {
                    request.setAttribute("e1", e1);
                    request.setAttribute("e2", e2);
                    request.setAttribute("e3", e3);
                    RequestDispatcher rd = request.getRequestDispatcher("changeuserinfo.jsp");
                    rd.forward(request, response);
                }
            } else if (button.equals("Logout")) {
                session.setAttribute("username", null);
                if (cookies.length > 0) {
                    for (int i = 0; i < cookies.length; i++) {
                        String name = cookies[i].getName();
                        String value = cookies[i].getValue();
                        if (name.equals("username")) {
                            session.invalidate();
                            Cookie cookie = new Cookie("username", null);
                            cookie.setMaxAge(0);
                            response.addCookie(cookie);
                            RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
                            rd.forward(request, response);
                        }
                    }
                } else {
                    session.invalidate();
                    response.sendRedirect("index.jsp");
                }
            } else if (button.equals("Access")) {
                String type = request.getParameter("type");
                if (type.equals("album")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote = (AlbumSessionBeanRemote) obj;
                    List list = remote.loadAlbum();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "album");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("artist")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("ArtistsJNDI");
                    ArtistsSessionBeanRemote remote = (ArtistsSessionBeanRemote) obj;
                    List list = remote.loadArtist();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "artist");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("comment")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("CommentsJNDI");
                    CommentsSessionBeanRemote remote = (CommentsSessionBeanRemote) obj;
                    List list = remote.loadComment();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "comment");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("country")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("CountryJNDI");
                    CountrySessionBeanRemote remote = (CountrySessionBeanRemote) obj;
                    List list = remote.loadCountry();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "country");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("genre")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("GenresJNDI");
                    GenresSessionBeanRemote remote = (GenresSessionBeanRemote) obj;
                    List list = remote.loadGenre();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "genre");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("musician")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("MusiciansJNDI");
                    MusiciansSessionBeanRemote remote = (MusiciansSessionBeanRemote) obj;
                    List list = remote.loadMusician();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "musician");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("producer")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("ProducersJNDI");
                    ProducersSessionBeanRemote remote = (ProducersSessionBeanRemote) obj;
                    List list = remote.loadProducer();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "producer");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("song")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("SongsJNDI");
                    SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                    List list = remote.loadSong();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "song");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("upload")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("UploadsJNDI");
                    UploadsSessionBeanRemote remote = (UploadsSessionBeanRemote) obj;
                    List list = remote.loadUpload();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "upload");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                } else if (type.equals("user")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("UsersJNDI");
                    UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                    List list = remote.loadUser();
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "user");
                    RequestDispatcher rd = request.getRequestDispatcher("adminhomepage.jsp");
                    rd.forward(request, response);
                }
            } else if (button.equals("View")) {
                String type = request.getParameter("type");
                if (type.equals("album")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote = (AlbumSessionBeanRemote) obj;
                    List list = remote.getAlbum(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "album");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("artist")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("ArtistsJNDI");
                    ArtistsSessionBeanRemote remote = (ArtistsSessionBeanRemote) obj;
                    List list = remote.getArtist(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "artist");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("comment")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("CommentsJNDI");
                    CommentsSessionBeanRemote remote = (CommentsSessionBeanRemote) obj;
                    List list = remote.getComment(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "comment");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("country")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("CountryJNDI");
                    CountrySessionBeanRemote remote = (CountrySessionBeanRemote) obj;
                    List list = remote.getCountry(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "country");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("genre")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("GenresJNDI");
                    GenresSessionBeanRemote remote = (GenresSessionBeanRemote) obj;
                    List list = remote.getGenre(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "genre");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("musician")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("MusiciansJNDI");
                    MusiciansSessionBeanRemote remote = (MusiciansSessionBeanRemote) obj;
                    List list = remote.getMusician(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "musician");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("producer")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("ProducersJNDI");
                    ProducersSessionBeanRemote remote = (ProducersSessionBeanRemote) obj;
                    List list = remote.getProducer(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "producer");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("song")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("SongsJNDI");
                    SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                    List list = remote.getSong(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "song");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("upload")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("UploadsJNDI");
                    UploadsSessionBeanRemote remote = (UploadsSessionBeanRemote) obj;
                    List list = remote.getUpload(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "upload");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                } else if (type.equals("user")) {
                    String name = request.getParameter("id");
                    Context context = new InitialContext();
                    Object obj = context.lookup("UsersJNDI");
                    UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                    List list = remote.getUser(name);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "user");
                    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
                    rd.forward(request, response);
                }
            } else if (button.equals("Edit")) {
                String type = request.getParameter("type");
                if (type.equals("album")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote = (AlbumSessionBeanRemote) obj;
                    List list = remote.getAlbum(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "album");
                    RequestDispatcher rd = request.getRequestDispatcher("edit.jsp");
                    rd.forward(request, response);
                } else if (type.equals("comment")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("CommentsJNDI");
                    CommentsSessionBeanRemote remote = (CommentsSessionBeanRemote) obj;
                    List list = remote.getComment(id);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "comment");
                    RequestDispatcher rd = request.getRequestDispatcher("edit.jsp");
                    rd.forward(request, response);
                } else if (type.equals("song")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("ArtistsJNDI");
                    ArtistsSessionBeanRemote remote = (ArtistsSessionBeanRemote) obj;
                    List list1 = remote.loadArtist();
                    request.setAttribute("artist", list1);
                    obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote1 = (AlbumSessionBeanRemote) obj;
                    List list2 = remote1.loadAlbum();
                    request.setAttribute("album", list2);
                    obj = context.lookup("GenresJNDI");
                    GenresSessionBeanRemote remote2 = (GenresSessionBeanRemote) obj;
                    List list3 = remote2.loadGenre();
                    request.setAttribute("genre", list3);
                    obj = context.lookup("ProducersJNDI");
                    ProducersSessionBeanRemote remote3 = (ProducersSessionBeanRemote) obj;
                    List list4 = remote3.loadProducer();
                    request.setAttribute("producer", list4);
                    obj = context.lookup("CountryJNDI");
                    CountrySessionBeanRemote remote4 = (CountrySessionBeanRemote) obj;
                    List list5 = remote4.loadCountry();
                    request.setAttribute("country", list5);
                    obj = context.lookup("MusiciansJNDI");
                    MusiciansSessionBeanRemote remote5 = (MusiciansSessionBeanRemote) obj;
                    List list6 = remote5.loadMusician();
                    request.setAttribute("musician", list6);
                    request.setAttribute("type", "song");
                    obj = context.lookup("SongsJNDI");
                    SongsSessionBeanRemote remote6 = (SongsSessionBeanRemote) obj;
                    List list7 = remote6.getSong(id);
                    request.setAttribute("LIST", list7);
                    RequestDispatcher rd = request.getRequestDispatcher("edit.jsp");
                    rd.forward(request, response);
                } else if (type.equals("user")) {
                    String name = request.getParameter("id");
                    Context context = new InitialContext();
                    Object obj = context.lookup("UsersJNDI");
                    UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                    List list = remote.getUser(name);
                    request.setAttribute("LIST", list);
                    request.setAttribute("type", "user");
                    RequestDispatcher rd = request.getRequestDispatcher("edit.jsp");
                    rd.forward(request, response);
                }
            } else if (button.equals("Back")) {
                String type = request.getParameter("type");
                Context context = new InitialContext();
                Object obj = context.lookup("ArtistsJNDI");
                ArtistsSessionBeanRemote remote = (ArtistsSessionBeanRemote) obj;
                List list = remote.loadArtist();
                request.setAttribute("LIST", list);
                request.setAttribute("type", "artist");
                RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=" + type);
                rd.forward(request, response);
            } else if (button.equals("Save")) {
                String type = request.getParameter("type");
                if (type.equals("album")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    String url = request.getParameter("url");
                    Context context = new InitialContext();
                    Object obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote = (AlbumSessionBeanRemote) obj;
                    boolean result = remote.saveAlbum(id, url);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=album");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("comment")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    String content = request.getParameter("content");
                    Context context = new InitialContext();
                    Object obj = context.lookup("CommentsJNDI");
                    CommentsSessionBeanRemote remote = (CommentsSessionBeanRemote) obj;
                    boolean result = remote.saveComment(id, content);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=comment");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("song")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    String name = request.getParameter("name");
                    int artist = Integer.parseInt(request.getParameterValues("artist")[0]);
                    int album = Integer.parseInt(request.getParameterValues("album")[0]);
                    int genre = Integer.parseInt(request.getParameterValues("genre")[0]);
                    int producer = Integer.parseInt(request.getParameterValues("producer")[0]);
                    int country = Integer.parseInt(request.getParameterValues("country")[0]);
                    int musician = Integer.parseInt(request.getParameterValues("musician")[0]);
                    int year = 0;
                    if (request.getParameter("no").equals("")) {
                        year = Integer.parseInt(request.getParameter("year"));
                    }
                    boolean isSong = Boolean.parseBoolean(request.getParameter("isSong"));
                    int no = 0;
                    if (request.getParameter("no").equals("")) {
                        no = Integer.parseInt(request.getParameter("no"));
                    }
                    String lyric = request.getParameter("lyric");
                    String l1 = request.getParameter("l1");
                    String l2 = request.getParameter("l2");
                    String l3 = request.getParameter("l3");
                    String l4 = request.getParameter("l4");
                    String d1 = request.getParameter("d1");
                    String d2 = request.getParameter("d2");
                    String d3 = request.getParameter("d3");
                    String d4 = request.getParameter("d4");
                    String thumbnail = request.getParameter("thumbnail");
                    Context context = new InitialContext();
                    Object obj = context.lookup("SongsJNDI");
                    SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                    boolean result = remote.saveSong(id, name, artist, album, genre, producer, lyric, country, musician, year, 0, 0, no, isSong, l1, l2, l3, l4, d1, d2, d3, d4, thumbnail);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=song");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("user")) {
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");
                    String email = request.getParameter("email");
                    boolean isAdmin = Boolean.parseBoolean(request.getParameterValues("role")[0]);
                    Context context = new InitialContext();
                    Object obj = context.lookup("UsersJNDI");
                    UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                    boolean result = remote.saveUser(username, password, email, isAdmin);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=user");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                }
            } else if (button.equals("Delete")) {
                String type = request.getParameter("type");
                if (type.equals("album")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote = (AlbumSessionBeanRemote) obj;
                    boolean result = remote.deleteAlbum(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=album");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("artist")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("ArtistsJNDI");
                    ArtistsSessionBeanRemote remote = (ArtistsSessionBeanRemote) obj;
                    boolean result = remote.deleteArtist(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=artist");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("comment")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("CommentsJNDI");
                    CommentsSessionBeanRemote remote = (CommentsSessionBeanRemote) obj;
                    boolean result = remote.deleteComment(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=comment");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("country")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("CountryJNDI");
                    CountrySessionBeanRemote remote = (CountrySessionBeanRemote) obj;
                    boolean result1 = remote.deleteCountry(id);
                    if (result1) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=country");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("genre")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("GenresJNDI");
                    GenresSessionBeanRemote remote = (GenresSessionBeanRemote) obj;
                    boolean result = remote.deleteGenre(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=genre");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("musician")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("MusiciansJNDI");
                    MusiciansSessionBeanRemote remote = (MusiciansSessionBeanRemote) obj;
                    boolean result = remote.deleteMusician(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=musician");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("producer")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("ProducersJNDI");
                    ProducersSessionBeanRemote remote = (ProducersSessionBeanRemote) obj;
                    boolean result = remote.deleteProducer(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=producer");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("song")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("SongsJNDI");
                    SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                    boolean result = remote.deleteSong(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=song");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("upload")) {
                    int id = Integer.parseInt(request.getParameter("id"));
                    Context context = new InitialContext();
                    Object obj = context.lookup("UploadsJNDI");
                    UploadsSessionBeanRemote remote = (UploadsSessionBeanRemote) obj;
                    boolean result = remote.deleteUpload(id);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=upload");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("user")) {
                    String username = request.getParameter("id");
                    Context context = new InitialContext();
                    Object obj = context.lookup("UsersJNDI");
                    UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                    boolean result = remote.deleteUser(username);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=user");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                }
            } else if (button.equals("Add")) {
                String type = request.getParameter("type");
                if (type.equals("album")) {
                    request.setAttribute("type", "album");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                } else if (type.equals("artist")) {
                    request.setAttribute("type", "artist");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                } else if (type.equals("country")) {
                    request.setAttribute("type", "country");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                } else if (type.equals("genre")) {
                    request.setAttribute("type", "genre");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                } else if (type.equals("musician")) {
                    request.setAttribute("type", "musician");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                } else if (type.equals("producer")) {
                    request.setAttribute("type", "producer");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                } else if (type.equals("song")) {
                    Context context = new InitialContext();
                    Object obj = context.lookup("ArtistsJNDI");
                    ArtistsSessionBeanRemote remote = (ArtistsSessionBeanRemote) obj;
                    List list1 = remote.loadArtist();
                    request.setAttribute("artist", list1);
                    obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote1 = (AlbumSessionBeanRemote) obj;
                    List list2 = remote1.loadAlbum();
                    request.setAttribute("album", list2);
                    obj = context.lookup("GenresJNDI");
                    GenresSessionBeanRemote remote2 = (GenresSessionBeanRemote) obj;
                    List list3 = remote2.loadGenre();
                    request.setAttribute("genre", list3);
                    obj = context.lookup("ProducersJNDI");
                    ProducersSessionBeanRemote remote3 = (ProducersSessionBeanRemote) obj;
                    List list4 = remote3.loadProducer();
                    request.setAttribute("producer", list4);
                    obj = context.lookup("CountryJNDI");
                    CountrySessionBeanRemote remote4 = (CountrySessionBeanRemote) obj;
                    List list5 = remote4.loadCountry();
                    request.setAttribute("country", list5);
                    obj = context.lookup("MusiciansJNDI");
                    MusiciansSessionBeanRemote remote5 = (MusiciansSessionBeanRemote) obj;
                    List list6 = remote5.loadMusician();
                    request.setAttribute("musician", list6);
                    request.setAttribute("type", "song");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                } else if (type.equals("user")) {
                    request.setAttribute("type", "user");
                    RequestDispatcher rd = request.getRequestDispatcher("add.jsp");
                    rd.forward(request, response);
                }
            } else if (button.equals("Add New")) {
                String type = request.getParameter("type");
                if (type.equals("album")) {
                    String name = request.getParameter("name");
                    String url = request.getParameter("url");
                    Context context = new InitialContext();
                    Object obj = context.lookup("AlbumsJNDI");
                    AlbumSessionBeanRemote remote = (AlbumSessionBeanRemote) obj;
                    boolean result = remote.addAlbum(name, url);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=album");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("artist")) {
                    String name = request.getParameter("name");
                    Context context = new InitialContext();
                    Object obj = context.lookup("ArtistsJNDI");
                    ArtistsSessionBeanRemote remote = (ArtistsSessionBeanRemote) obj;
                    boolean result = remote.addArtist(name);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=artist");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("country")) {
                    String name = request.getParameter("name");
                    Context context = new InitialContext();
                    Object obj = context.lookup("CountryJNDI");
                    CountrySessionBeanRemote remote = (CountrySessionBeanRemote) obj;
                    boolean result = remote.addCountry(name);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=country");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("genre")) {
                    String name = request.getParameter("name");
                    Context context = new InitialContext();
                    Object obj = context.lookup("GenresJNDI");
                    GenresSessionBeanRemote remote = (GenresSessionBeanRemote) obj;
                    boolean result = remote.addGenre(name);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=genre");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("musician")) {
                    String name = request.getParameter("name");
                    Context context = new InitialContext();
                    Object obj = context.lookup("MusiciansJNDI");
                    MusiciansSessionBeanRemote remote = (MusiciansSessionBeanRemote) obj;
                    boolean result = remote.addMusician(name);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=musician");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("producer")) {
                    String name = request.getParameter("name");
                    Context context = new InitialContext();
                    Object obj = context.lookup("ProducersJNDI");
                    ProducersSessionBeanRemote remote = (ProducersSessionBeanRemote) obj;
                    boolean result = remote.addProducer(name);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=producer");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("song")) {
                    String name = request.getParameter("name");
                    int artist = Integer.parseInt(request.getParameterValues("artist")[0]);
                    int album = Integer.parseInt(request.getParameterValues("album")[0]);
                    int genre = Integer.parseInt(request.getParameterValues("genre")[0]);
                    int producer = Integer.parseInt(request.getParameterValues("producer")[0]);
                    int country = Integer.parseInt(request.getParameterValues("country")[0]);
                    int musician = Integer.parseInt(request.getParameterValues("musician")[0]);
                    int year = 0;
                    if (request.getParameter("no").equals("")) {
                        year = Integer.parseInt(request.getParameter("year"));
                    }
                    boolean isSong = Boolean.parseBoolean(request.getParameter("isSong"));
                    int no = 0;
                    if (request.getParameter("no").equals("")) {
                        no = Integer.parseInt(request.getParameter("no"));
                    }
                    String lyric = request.getParameter("lyric");
                    String l1 = request.getParameter("l1");
                    String l2 = request.getParameter("l2");
                    String l3 = request.getParameter("l3");
                    String l4 = request.getParameter("l4");
                    String d1 = request.getParameter("d1");
                    String d2 = request.getParameter("d2");
                    String d3 = request.getParameter("d3");
                    String d4 = request.getParameter("d4");
                    String thumbnail = request.getParameter("thumbnail");
                    Context context = new InitialContext();
                    Object obj = context.lookup("SongsJNDI");
                    SongsSessionBeanRemote remote = (SongsSessionBeanRemote) obj;
                    boolean result = remote.addSong(name, artist, album, genre, producer, lyric, country, musician, year, 0, 0, no, isSong, l1, l2, l3, l4, d1, d2, d3, d4, thumbnail);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=song");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                } else if (type.equals("upload")) {
                } else if (type.equals("user")) {
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");
                    String email = request.getParameter("email");
                    boolean isAdmin = Boolean.parseBoolean(request.getParameterValues("role")[0]);
                    Calendar cal = Calendar.getInstance();
                    Date date = cal.getTime();
                    Context context = new InitialContext();
                    Object obj = context.lookup("UsersJNDI");
                    UsersSessionBeanRemote remote = (UsersSessionBeanRemote) obj;
                    boolean result = remote.addUser(username, password, date, email, isAdmin, 0);
                    if (result) {
                        RequestDispatcher rd = request.getRequestDispatcher("ControllerServlet?btnAction=Access&type=user");
                        rd.forward(request, response);
                    } else {
                        RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
                        rd.forward(request, response);
                    }
                }
            }
        } catch (NamingException ex) {
            Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            out.close();


        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);


    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);


    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";

    }// </editor-fold>
}
